package com.txd.mofa.shouye.aty;

import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;

import com.bumptech.glide.Glide;
import com.kongzue.baseframework.BaseFragment;
import com.kongzue.baseframework.interfaces.Layout;
import com.kongzue.baseframework.util.JumpParameter;
import com.txd.mofa.R;
import com.txd.mofa.adapter.BiaoqianAdapter;
import com.txd.mofa.base.BaseAty;
import com.txd.mofa.net.NetUtils;
import com.txd.mofa.shouye.fgt.ShipinFgt;
import com.txd.mofa.shouye.fgt.TupianFgt;
import com.txd.mofa.view.MyViewPager;
import com.txd.mofa.view.ViewPagerAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.jzvd.Jzvd;

@Layout(R.layout.aty_xiangqing)
public class XiangqingAty extends BaseAty {

    private ImageView iv_back,iv,iv1,iv_zhuanfa,iv_sc,iv_qiehuan;
    private MyViewPager viewpager;
    private List<BaseFragment> fragments = new ArrayList<>();
    private RecyclerView recy;

    @Override
    public void initViews() {
        super.initViews();

        iv_sc = findViewById(R.id.iv_sc);
        iv_qiehuan = findViewById(R.id.iv_qiehuan);
        iv_zhuanfa = findViewById(R.id.iv_zhuanfa);
        iv_back = findViewById(R.id.iv_back);
        iv = findViewById(R.id.iv);
        iv1 = findViewById(R.id.iv1);
        viewpager = findViewById(R.id.viewPager);
        recy = findViewById(R.id.recy);

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(me);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        recy.setLayoutManager(linearLayoutManager);

        BiaoqianAdapter biaoqianAdapter = new BiaoqianAdapter(R.layout.item_biaoqian);
        recy.setAdapter(biaoqianAdapter);


        List<Map<String,String>> list = new ArrayList<>();
        for (int i = 0; i < 2;i++){
            Map<String,String> map = new HashMap<>();
            list.add(map);
        }
        biaoqianAdapter.setNewData(list);

        fragments.add(ShipinFgt.newInstance());
        fragments.add(TupianFgt.newInstance());


        ViewPagerAdapter viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager(), fragments);
        viewpager.setAdapter(viewPagerAdapter);
        viewpager.setOffscreenPageLimit(fragments.size());

        /**
         * 设置与viewpager关联
         */
        viewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {
                pos = i;
                switch (i) {
                    case 0:
                        iv.setVisibility(View.VISIBLE);
                        iv1.setVisibility(View.GONE);
                        break;
                    case 1:
                        iv.setVisibility(View.GONE);
                        iv1.setVisibility(View.VISIBLE);
                        break;

                }
            }

            @Override
            public void onPageSelected(int position) {

                Log.e("posss",position+"");
                pos = position;
                switch (position) {
                    case 0:
                        viewpager.setCurrentItem(0);
                        break;
                    case 1:
                        viewpager.setCurrentItem(1);
                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });


    }

    @Override
    protected void onNetworkConnected(NetUtils.NetType type) {

    }

    @Override
    protected void onNetworkDisConnected() {

    }

    @Override
    public void onBackPressed() {
        if (Jzvd.backPress()) {
            return;
        }
        super.onBackPressed();
    }
    @Override
    protected void onPause() {
        super.onPause();
        Jzvd.releaseAllVideos();
    }


    @Override
    public void initDatas(JumpParameter paramer) {

    }

    private int pos = 0;

    private String aaa = "1";
    private String a = "1";

    @Override
    public void setEvents() {

        iv_sc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (a.equals("1")){
                    Glide.with(me).load(R.mipmap.xiangq_sc_xuan).into(iv_sc);
                    a = "2";
                }else {
                    Glide.with(me).load(R.mipmap.xiangq_sc).into(iv_sc);
                    a = "1";
                }
            }
        });
        iv_qiehuan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (aaa.equals("1")){
                    Glide.with(me).load(R.mipmap.tihuan_xuan).into(iv_qiehuan);
                    aaa = "2";
                }else {
                    Glide.with(me).load(R.mipmap.tihuan).into(iv_qiehuan);
                    aaa = "1";
                }
            }
        });

        iv_zhuanfa.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                FenxiangDialog fenxiangDialog = new FenxiangDialog(me,pos, new FenxiangDialog.SignListener() {
//                    @Override
//                    public void jubao() {
//                        jump(JubaoAty.class);
//                    }
//
//                    @Override
//                    public void xiangce() {
//
//                    }
//
//                    @Override
//                    public void baocun() {
//
//                    }
//                });
//                fenxiangDialog.show();
            }
        });

        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                iv.setVisibility(View.GONE);
                iv1.setVisibility(View.VISIBLE);
                viewpager.setCurrentItem(1);
            }
        });
        iv1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                iv.setVisibility(View.VISIBLE);
                iv1.setVisibility(View.GONE);
                viewpager.setCurrentItem(0);
            }
        });
    }
}
